home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / comm / mail / thor201.lha / THOR_2.0 / thor.lha / rexx / UUEncode.thor < prev    next >
Text File  |  1995-05-15  |  5KB  |  197 lines

  1. /* UUEncode.thor by Troels Walsted Hansen
  2. ** $VER: UUEncode.thor v2.00 (01.11.94)
  3. **
  4. ** An ARexx script that uuencodes a file and either places it in the
  5. ** clipboard or posts a message for you containing the file. Using
  6. ** LhA, this script will archive the file if it isn't already.
  7. **
  8. ** Utilises LhA by Stefan Boberg for archiving.
  9. ** The script may use either of the following for uuencoding:
  10. **    · UUFast v1.25 by Jørn Halonen
  11. **    · uuIn v1.03 by Nicolas Dade
  12. **    · UUxT v3.0 by Asher Feldman
  13. **
  14. ** New: · This version is only for THOR v2.0 or higher.
  15. **      · A lot easier to adapt to other uuencoders and includes
  16. **        commandstrings for uuIn, UUFast and UUxT.
  17. **      · Doesn't require rexxsupport.library anymore.
  18. **      · Doesn't require MagicClip anymore.
  19. */
  20.  
  21. /* some user variables. edit to your hearts content */
  22.  
  23. tmpdir = "T:"        /* Work dir for the encoding    */
  24. uuencoder = "uuin"    /* may be: uuin, uufast or uuxt */
  25.  
  26. /* needs THOR and bbsread.library functions */
  27.  
  28. options results
  29.  
  30. p = address() || ' ' || show('P',,)
  31. thorport = pos('THOR.',p)
  32.  
  33. if thorport > 0 then thorport = word(substr(p,thorport),1)
  34. else
  35. do
  36.     say 'No THOR port found!'
  37.     exit 10
  38. end
  39.  
  40. if ~show('p', 'BBSREAD') then
  41. do
  42.     address command
  43.         "run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead"
  44.         "WaitForPort BBSREAD"
  45. end
  46.  
  47. /* get filename */
  48.  
  49. address(bbsread)
  50. GETGLOBALDATA STEM GLOBALDATA
  51.  
  52. address(thorport)
  53. THORTOFRONT
  54. REQUESTFILE TITLE '"Select file to encode:"' ID '"'GLOBALDATA.UPLOADPATH'"' FP PAT '"#?"'
  55. if(rc ~= 0) then exit
  56.  
  57. filetoencode = result
  58. lastchar = right(filetoencode,1)
  59.  
  60. if(lastchar = "/" | lastchar = ":" | filetoencode = "") then
  61. do
  62.     REQUESTNOTIFY TEXT '"No file selected!"' BT '"_Ok"'
  63.     call CleanUp()
  64. end
  65.  
  66. posi = lastpos("/",FileToEncode)
  67. if(posi = 0) then posi = lastpos(":",FileToEncode)
  68. WithoutPath = substr(FileToEncode,posi+1)
  69.  
  70. /* if file isn't LhA'ed -- do it ourselves */
  71.  
  72. extension = upper(substr(FileToEncode, lastpos(".",FileToEncode)+1))
  73.  
  74. if~(extension = "LHA" | extension = "LZH") then
  75. do
  76.     REQUESTNOTIFY TEXT '"Do you want to LhA the file?"' BT '"_Yes|_No"'
  77.     if(result) then
  78.     do
  79.         address command "LhA >nil: -y -q a "||'"'tmpdir||WithoutPath'"'||" "||'"'FileToEncode'"'
  80.  
  81.         if(rc ~= 0) then REQUESTNOTIFY TEXT '"LhA''ing did not succeed."' BT '"_Ok"'
  82.         else FileToEncode = tmpdir||WithoutPath||".lha"
  83.     end
  84. end
  85.  
  86. /* select correct uuencoder commandstring */
  87.  
  88. select
  89.     when(uuencoder = 'uufast') then cmd = "UUFast >nil: " || '"' || filetoencode || '"' || " TO " || tmpdir || "Message.uu E"
  90.     when(uuencoder = 'uuin') then cmd = "uuIn >nil: INFILE=" || '"' || filetoencode || '"' || " OUTFILE=" || tmpdir || "Message.uu"
  91.     when(uuencoder = 'uuxt') then cmd = 'UUxT >nil: a ' || tmpdir || 'Message.uu ' || '"'filetoencode'"'
  92.     otherwise
  93.     do
  94.         REQUESTNOTIFY TEXT '"UUEncoder not configured correctly."' BT '"_Ok"'
  95.         call CleanUp()
  96.     end
  97. end
  98. address command cmd
  99.  
  100. if ~exists(tmpdir"Message.uu") then
  101. do
  102.     REQUESTNOTIFY TEXT '"Something went wrong during uuencoding."' BT '"_Ok"'
  103.     call CleanUp()
  104. end
  105.  
  106. REQUESTNOTIFY TEXT '"Place in clipboard or post as a message?"' BT '"Clip_board|_Post|_Cancel"'
  107. choice = result
  108.  
  109. if(choice = 1) then
  110. do
  111.     PUTCLIP unit 0 file '"'tmpdir'Message.uu"'
  112.     if(rc ~= 0) then
  113.     do
  114.         address(thorport)
  115.         REQUESTNOTIFY TEXT '"'THOR.LASTERROR'"' BT '"_Ok"'
  116.         exit 5
  117.     end
  118. end
  119. else if(choice = 2) then
  120. do
  121.     drop EVENT.
  122.     address(bbsread)
  123.  
  124.     GETBBSLIST stem BBSLIST
  125.     if(rc ~= 0) then
  126.     do
  127.         address(thorport)
  128.         REQUESTNOTIFY TEXT '"'BBSREAD.LASTERROR'"' BT '"_Ok"'
  129.         exit 5
  130.     end
  131.  
  132.     address(thorport)
  133.  
  134.     REQUESTLIST instem BBSLIST title '"Select BBS:"' SIZEGADGET
  135.     if(rc ~= 0) then break
  136.     else bbs = result
  137.  
  138.     address(bbsread)
  139.         GETCONFLIST '"'bbs'"' CONFLIST
  140.     if(rc ~= 0) then
  141.     do
  142.         address(thorport)
  143.         REQUESTNOTIFY TEXT '"'BBSREAD.LASTERROR'"' BT '"_Ok"'
  144.         exit 5
  145.     end
  146.  
  147.     address(thorport)
  148.  
  149.     REQUESTLIST instem CONFLIST title '"Select conf:"' SIZEGADGET
  150.     if(rc ~= 0) then break
  151.     else EVENT.CONFERENCE = result
  152.  
  153.     REQUESTSTRING TITLE '"Please enter subject of message:"' BT '"_Ok|_Cancel"' ID '"'WithoutPath'"' MAXCHARS 100
  154.     EVENT.SUBJECT = result
  155.     if(rc ~= 0 | EVENT.SUBJECT = "") then break
  156.  
  157.     REQUESTSTRING TITLE '"Please enter receiver name:"' BT '"_Ok|_Cancel"' ID '"ALL"' MAXCHARS 100
  158.     EVENT.TONAME = result
  159.     if(rc ~= 0 | EVENT.TONAME = "") then break
  160.  
  161.     address(bbsread)
  162.     UNIQUEMSGFILE bbsname '"'bbs'"' stem UNIQUEFILE
  163.     if(rc ~= 0) then
  164.     do
  165.         address(thorport)
  166.         REQUESTNOTIFY TEXT '"'BBSREAD.LASTERROR'"' BT '"_Ok"'
  167.         exit
  168.     end
  169.  
  170.     address command 'copy >nil: ' || tmpdir || 'Message.uu TO ' || UNIQUEFILE.NAME
  171.     EVENT.MSGFILE = UNIQUEFILE.FILEPART
  172.  
  173.     WRITEBREVENT bbsname '"'bbs'"' event 0 stem EVENT
  174.     if(rc ~= 0) then
  175.     do
  176.         address(thorport)
  177.         REQUESTNOTIFY TEXT '"'BBSREAD.LASTERROR'"' BT '"_Ok"'
  178.         exit 5
  179.     end
  180.     else
  181.     do
  182.         address(thorport)
  183.         PACKEVENTS '"'bbs'"'
  184.         RESCAN
  185.     end
  186. end
  187.  
  188. call CleanUp()
  189.  
  190. /* cleanup and exit */
  191.  
  192. CleanUp:
  193.     if(exists(tmpdir || WithoutPath || ".lha")) then address command 'delete >nil: ' || '"' || tmpdir || WithoutPath || '.lha' || '"'
  194.     if(exists(tmpdir || "Message.uu")) then address command 'delete >nil: ' || tmpdir || 'Message.uu'
  195.     exit
  196. return
  197.